// WordCommand.h: interface for the WordCommand class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_WORDCOMMAND_H__08063E57_DD5E_440A_95AE_EE062B928080__INCLUDED_)
#define AFX_WORDCOMMAND_H__08063E57_DD5E_440A_95AE_EE062B928080__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "StdAfx.h"
#include "stdWord.h"
#include "SentencesSet.h"

// #define foreach(var, list, type) 
//     for (type::iterator var = list.begin(); var != list.end(); var++)
#define foreach(elementType, element, containerType, container) \
    for (containerType::iterator iter = container.begin(); iter != container.end(); iter++)\
	for (bool go = true; go;)\
            for (elementType & element = *iter;go; go=false)
class WordCommand  
{
public:
	WordCommand();
	virtual ~WordCommand();
	CComPtr<MSWORD::_Application> m_spApplication;
	CComPtr<MSWORD::_Document> m_spDocument;
	CComPtr<MSWORD::Range> m_pRang[3], m_pRang1;
//	CComPtr<IWebBrowser2> m_spBrowser;
	HWND m_hwnd;
	CComBSTR m_FileVer;
	CComBSTR *m_ShortCut;

	int CommandLines(LPCSTR str);
	int m_iLength;
	CComBSTR m_Otext, m_Ttext;
	CComBSTR m_ocopy , m_tcopy;
	CComBSTR m_TemplateFileName;
	CString m_filename;
	MSWORD::Template* m_TemplateFile;

private:
	long m_lDiskId;
	LPCSTR m_strCommand;
	
protected:

	int CompCommand();
	int SaveSentence();
	int SetCloseOpenGetCommand(int cmd, int param);
	int CopySourceCommand(int cmd, int param);
	int RestoreSourceCommand(LPCSTR cmd, int param);
	int CloseCommand(LPCSTR cmd, int param);
	int OpenCommand(LPCSTR cmd, int param);
	int WCommand(LPCSTR cmd, LPCSTR val);

	HRESULT InitRange(void);
	HRESULT Get_ParRanges();
	HRESULT fNextTextParagraph();
	HRESULT Get_CatRanges( int k );

	HRESULT Get_EditParRanges();

	HRESULT fThreeParagraphChar();
	HRESULT fThreeParagraphChar2();
	HRESULT fThreeParagraphChar3();
	HRESULT TrimSentence(MSWORD::Range* range);
	HRESULT Get_CurrentRange();
	HRESULT OpenCloseRestoreAction( int action, int i);
	HRESULT OpenCloseRestoreAction2( int action, int i);
	LRESULT Get_RangeState( int i );
	LRESULT Open_RangeStatus( int i , int k );
	LRESULT Close_RangeStatus( int i , int k );
	LRESULT Restore_RangeStatus( int i , int k);
	VOID Add_EditBookMark();
	VOID Delete_EditBookMark();
	HRESULT Set_EditMode( MSWORD::Range* r , CComBSTR bstr, CComBSTR btstr);
public:
	HRESULT InstallCatAddin();
	HRESULT Init_WordApplication();
	HRESULT Init_WordTemplate( int action);
	HRESULT WordCommandIndex(int index, int param);
	VARIANT_BOOL m_bcatbook ;

private:
//	CComBSTR UrlEncode(LPBSTR text);
	MSWORD::Range* m_ScRange[500], *CatRange[4];
	int m_nScRange, m_nCurrentRange ; 
	CComBSTR catcs[6], orgcs[4], catbookmark ;
	MSWORD::Range *m_EditRang;
	MSWORD::Range *m_SelectRange[4];
	MSWORD::Bookmarks* m_marks; 		MSWORD::Bookmark *bookmark;
	MSWORD::Selection* m_selection; CComBSTR m_SelectedText;
	MSWORD::Style* m_pCatStyle[6];
	MSWORD::Styles* m_pStyles;
	long bold, italic; float size; 
	long m_cmd; 
	VARIANT_BOOL m_ShowHiddenText;
	MSWORD::View *m_view;
	CComBSTR m_Postdata;

protected:
	BOOLEAN m_runing;
	friend void CALLBACK TimerProc(HWND hWnd,UINT nMsg,UINT nTimerid,DWORD dwTime); 
	
	//HRESULT GetPostData(LPVARIANT pvPostData );// , LPCTSTR cszPostData);
	HRESULT GetPostString( int action );
	HRESULT GetPostData(LPVARIANT pvPostData, int action);
};

#endif // !defined(AFX_WORDCOMMAND_H__08063E57_DD5E_440A_95AE_EE062B928080__INCLUDED_)

